/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package me.minetsh.imaging.sample;

import de.hdodenhof.circleimageview.CircleImageView;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.global.resource.NotExistException;
import ohos.global.resource.ResourceManager;
import ohos.global.resource.WrongTypeException;

import java.io.IOException;

/**
 * MainAbility
 *
 * @since 2021-07-27
 */
public class MainAbility extends Ability {
    private CircleImageView sdv_image_edit, sdv_image_album;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        ResourceManager resManager = this.getResourceManager();
        try {
            int color = resManager.getElement(ResourceTable.Color_colorPrimaryDark).getColor();
            getWindow().setStatusBarColor(color);
        } catch (IOException | NotExistException | WrongTypeException e) {
            e.fillInStackTrace();
        }

        sdv_image_edit = (CircleImageView) findComponentById(ResourceTable.Id_sdv_image_edit);
        sdv_image_album = (CircleImageView) findComponentById(ResourceTable.Id_sdv_image_album);

        sdv_image_edit.setClickedListener(component -> {
            launchAbility(new ImageEditSampleAbility());
        });

        sdv_image_album.setClickedListener(component -> {
            launchAbility(new GallerySampleAbility());
        });
    }

    private void launchAbility(Ability ability) {
        Intent intent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withBundleName(getBundleName())
                .withDeviceId("")
                .withAbilityName(ability.getClass().getName())
                .build();
        intent.setOperation(operation);
        startAbility(intent);
    }
}
